﻿﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>班级管理</title>
<#--freemarker引入模板文件，相对路径-->
    <#include "../common/link.ftl">

    <script>

        $(function () {
            //编辑新增按钮事件：打开莫泰框
            $('.btn_redirect').click(function () {
                //清模态框
                $('#editForm input').val('');
                //打开模态框
                var json = $(this).data('json');
                console.log(json);
                 //$('#editForm input[name="id"]').val(json.id);
                //编辑
                if (json) {
                    $('#editForm input[name="name"]').val(json.name);
                    $('#editForm input[name="number"]').val(json.number);
                    $('#employee').val(json.employeeId);
                }
                //打开模态框
                $('#myModal').modal('show');
            });

            //j-query-from插件：在有from表单提交异步请求时可以使用
            $('.btn-save').click(function () {
                //用j-query-from来提交异步表单
                $('#editForm').ajaxSubmit(handlerMessage);

            });

            //删除按钮
            $('.btn_delete').click(function () {
                var id = $(this).data('id');//拿id
                console.log(id);
                //提示
                $.messager.confirm("警告", "是否确认删除该数据", function () {
                    //发送ajax请求删除数据
                    $.get('/classInfo/delete.do', {id: id}, handlerMessage);
                })
            });


        })


    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">

<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">添加/编辑</h4>
            </div>
            <div class="modal-body">

            <#--input 表单-->
                <form class="form-horizontal btn-submit" action="/classInfo/saveOrUpdate.do" method="post"
                      id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">班级名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入班级名">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="number" class="col-sm-3 control-label">班级人数：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="number" name="number"
                                   placeholder="请输入班级人数">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="employee" class="col-sm-3 control-label">班主任：</label>
                        <div class="col-sm-5">
                            <div class="form-group">
                                <select class="form-control" id="employee" name="employeeId">

                                        <option value="-1">全部</option>
                                        <#list employees! as e>
                                            <option value="${(e.id)!}">${(e.name)!}</option>
                                        </#list>

                                </select>

                            </div>
                        </div>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-save">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<div class="wrapper">
    <#include "../common/navbar.ftl" >
    <!--菜单回显-->
    <#assign currentMenu="classInfo!"/>
    <#include "../common/menu.ftl" >
    <div class="content-wrapper">
        <section class="content-header">
            <h1>班级管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <form class="form-inline" id="searchForm" action="/classInfo/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label for="keyword">关键字:</label>
                            <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                                   placeholder="请输入班级名称">
                        </div>

                        <div class="form-group">
                            <label for="dept"> 班主任:</label>
                            <select class="form-control" id="employee" name="employeeId">
                                <option value="-1">全部</option>
                                <#list employees! as t>
                                    <option value="${(t.id)!}">${(t.name)!}</option>
                                </#list>
                            </select>
                            <script>
                                //回显
                                <#--$("#dept option[value='${qo.deptId}']").prop("selected", true);-->
                                //更简洁的方式
                                $('#employee').val(${qo.employeeId!})
                            </script>
                        </div>

                        <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <a href="#" class="btn btn-success btn_redirect" >
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                        <a href="#"
                           class="btn btn-danger btn_batchDelete">
                            <span class="glyphicon glyphicon-trash"></span> 批量删除
                        </a>
                    </form>
                </div>
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th><input id="allCb" type="checkbox"></th>
                        <th>编号</th>
                        <th>班级名称</th>
                        <th>班级人数</th>
                        <th>班主任</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <#--遍历查询结果显示出来-->
                    <#list result.list as classInfo>
                        <tr>
                            <td><input type="checkbox" class="cb" data-id="${classInfo.id}"></td>
                            <td>${classInfo_index + 1}</td>
                            <td>${classInfo.name!}</td>
                            <td>${classInfo.number!}</td>
                            <td>${(classInfo.employee.name)!}</td>
                            <td>
                            <#--<@shiro.hasRole name="classInfo:input">-->
                                <a href="#" class="btn btn-info btn-xs btn_redirect"
                                   data-json='${(classInfo.json)!}' data-id='${(classInfo.id)!}' data-emid='${(classInfo.employee.id)!}'>
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                            <#--</@shiro.hasRole>-->
                            <#--<@shiro.hasRole name="classInfo:delete">-->
                                <a href="#" data-id="${classInfo.id}"
                                   class="btn btn-danger btn-xs btn_delete">
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                            <#--</@shiro.hasRole>-->
                            </td>
                        </tr>
                    </#list>
                </table>
                <!--分页-->
                <#include "../common/page.ftl" >
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl" >
</div>
</body>
</html>
